<?php

declare(ENCODING = 'UTF-8');

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *	
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */	

/**
 * @package auxo
 * @subpackage Web 
 * @version $Id$
 */

/**	
 * The Translation Filter
 * 
 * This Filter translate the response content using a XML file. This file contains of marker and
 * translation for a list of languages. 
 *	
 * @package auxo
 * @subpackage Web
 * @version $Id$	
 * @copyright Copyright belongs to the respective authors
 * @author AHN
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */
 class tx_auxo_translatorFilter implements tx_auxo_FilterInterface {
 	
 	/**
 	 * Initializes this filter and creates and translator instance
 	 *
 	 * @param tx_auxo_Configuration $configuration
 	 * @return void
 	 */
 	public function initialize(tx_auxo_Configuration $configuration) {
		if (! $configuration->get('PathToLanguageFile')) {
			return void;
		}
		
		$this->translator = new tx_lib_translator();
		$this->translator->setPathToLanguageFile($configuration->get('PathToLanguageFile'));
 	}
 	
 	/**
 	 * Filters the response content by replacing placeholder with a translation text
 	 *
 	 * @param tx_auxo_Request $request a request
 	 * @param tx_auxo_Response $reqsponse a response
 	 * @param tx_auxo_FilterChain $chain a filter chain
 	 */
 	function filter(tx_auxo_Request $request, tx_auxo_Response $reqsponse, tx_auxo_FilterChain $chain) {
 		$chain->invoke($request, $response);
 		if ($this->translator) {
			$response->setContent($translator->translate($response->getContent()));		
 		}
 	}
}
?>